package com.fantasizegame.project.gen.utils;

import java.io.File;
import java.io.IOException;
import java.io.Writer;
import java.util.Map;

import freemarker.template.Configuration;
import freemarker.template.Template;
import freemarker.template.TemplateException;

public class FreemarkerUtils {

	private static Configuration cfg = new Configuration(Configuration.VERSION_2_3_0);

	static {
		try {
			cfg.setDirectoryForTemplateLoading(new File(FreemarkerUtils.class.getClassLoader().getResource("template").getFile()));
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	public static boolean general(String tname, Map<String, Object> datas, Writer writer) {
		try {
			Template template = cfg.getTemplate(tname);
			template.process(datas, writer);
			return true;
		} catch (IOException | TemplateException e) {
			e.printStackTrace();
		}
		return false;

	}

}
